<template>
	<view class="wanl-order-list">
		<view v-for="(order, okey) in orderList" :key="order.id" class="order-item radius-bock">
			<view class="head">
				<view class="shop wanl-gray" @tap="onShop(order.shop_id)">
					<text class="wlIcon-dianpu1 wanl-black"></text>
					<text class="wanl-black margin-lr-xs text-30">{{ order.shopname}}</text>
					<text class="wlIcon-fanhuigengduo text-sm">[{{ $wanlshop.timeToDate(order.createtime) }}]</text>
				</view>
			</view>
			<!-- 商品 -->
			<view class="goods-box">
				<view class="cu-avatar xl margin-right-bj radius" :style="{backgroundImage: 'url('+$wanlshop.oss(order.image, 70, 70)+')'}"> </view>
				<view class="content margin-right-bj">
					<view class="describe">
						<view class="text-cut-2">
							{{order.title}}
						</view>
					</view>
					<view class="parameter">						
						<view class="text-min wanl-gray">
							x {{ order.number }}
						</view>							
					</view>
				</view>
			</view>  
			<!-- 底部 -->
			<view class="price-box text-sm flex" v-if="order.state == 1">					      
				<view>可取货：<text>{{ (order.pre_delivertime <= Math.floor(Date.now()/1000))?'是':$wanlshop.timeFormat(order.pre_delivertime) }}</text></view>
			</view>	
		</view>
		
		<view style="height: 80rpx;margin: 20rpx;">
			<text style="margin: 10px;">买家：{{nickname}}, 电话：{{mobile}}</text>		
			<button class="cu-btn round margin-lr-bj wanl-bg-orange" style="width: 100%;margin: 30px auto;font-size: 18px;"   @tap="take">{{taketext}}</button>						
		</view>

	</view>
</template>

<script>

export default {
	data() {
		return {
			orderList:[],
			text:'',
			nickname:'',
			mobile:'',
			tt:false,
			taketext:'确认提货'
		};
	},
	onLoad(options) {
		console.log(options);
		this.text = options.text;
	
		this.loadData();		
	},
	methods: {
		//获取订单列表
		async loadData(source) {			
			// 获取列表
		  
			await uni.request({
				url: '/wanlshop/ddporder/getTakeList',		
				method:'POST',
				data:{text:this.text},
				success: res => {
					console.log(res);
					this.orderList = res.data;
					this.nickname = res.data['0'].nickname;
					this.mobile = res.data['0'].mobile;
				}
			});
		},
		async take(){		
			console.log(this.tt);
			if(this.tt)return;
			let that = this;
			await uni.showModal({
					title: '提示：',
					content: '确认提货？',
					success: function(res) {
						if (res.confirm) {
							uni.request({
								url: '/wanlshop/ddporder/takeConfirm',
								data: {
									text: that.text
								},
								method:'POST',
								success: res => {
									that.taketext = '已提货';
									that.tt = true;
									console.log(res);
									this.$wanlshop.back(1);
								}
							});
						} else if (res.cancel) {							
							return
						}
					}
			});

		}		 
	
	}
};
</script>

<style>
page {
	height: 100%;
}
</style>
